from flask import Flask, make_response, request, render_template
from flask_cors import CORS
from api.onepage import onepage_api
from api.zhuanlan import zhuanlan_api
import os

app = Flask(__name__)
CORS(app, expose_headers=["Content-Disposition"])
app.config['STATIC_FOLDER'] = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static')
app.register_blueprint(onepage_api, url_prefix='/one')
app.register_blueprint(zhuanlan_api, url_prefix='/zl')

app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600 # 缓存时间为1小时

@app.route('/static/<path:filename>')
def static_files(filename):
    from flask import send_from_directory
    return send_from_directory(app.config['STATIC_FOLDER'], filename)


@app.route('/', methods=['GET', 'POST'])
def run():
    if request.method == 'POST':
        data = request.form.get('url', type=str)
        print(data)
        return make_response({'message': 'Data received'}, 200)
    else:
        # return make_response({'message': 'Hello World!'}, 200)
        return render_template('index.html')


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True, threaded=True)
